#include "ClientSingle.h"

ClientSingle *ClientSingle::getInstance()
{
    static ClientSingle *instance = new ClientSingle;
    return instance;
}

/* 添加客户端信息 */
void ClientSingle::InsertClientInfo(std::string &username, StdTcpSocketPtr clientPtr)
{
    std::lock_guard locker(g_clientInfoMutex);  //作用域在括号之内

    m_clientInfoList[username] = clientPtr;
}

/* 获取客户端信息 */
StdTcpSocketPtr ClientSingle::GetTargetClientInfo(std::string &username)
{
    std::lock_guard locker(g_clientInfoMutex);

    auto iter = m_clientInfoList.find(username);
    if (iter != m_clientInfoList.end())
    {
        return iter->second;
    }

    return nullptr;
}

